home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / network / lattice / portlib.lzh / PORTLIB / ITIMER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-27  |  1.8 KB  |  85 lines

  1. #include <osbind.h>
  2. #include <unistd.h>
  3. #include <signal.h>
  4. #include <errno.h>
  5. #include <sys/time.h>
  6. #include "itimer.h"
  7.  
  8. #ifndef Tsetitimer
  9. #define trap_1_wwllll(n, a, b, c, d, e)                    \
  10. __extension__                                \
  11. ({                                    \
  12.     register long retvalue __asm__("d0");                \
  13.     short _a = (short)(a);                        \
  14.     long  _b = (long) (b);                        \
  15.     long  _c = (long) (c);                        \
  16.     long  _d = (long) (d);                        \
  17.     long  _e = (long) (e);                        \
  18.                                         \
  19.     __asm__ volatile                        \
  20.     ("\
  21.         movl    %6,sp@-; \
  22.         movl    %5,sp@-; \
  23.         movl    %4,sp@-; \
  24.         movl    %3,sp@-; \
  25.         movw    %2,sp@-; \
  26.         movw    %1,sp@-; \
  27.         trap    #1;    \
  28.         lea    sp@(20),sp "                    \
  29.     : "=r"(retvalue)            /* outputs */        \
  30.     : "g"(n), "r"(_a), "r"(_b), "r"(_c), "r"(_d), "r"(_e)        \
  31.     : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */    \
  32.       AND_MEMORY                            \
  33.     );                                \
  34.     retvalue;                            \
  35. })
  36.  
  37. #define Tsetitimer(w,ni,nv,oi,ov) \
  38.     trap_1_wwllll (0x149, (short)w, (long)ni, (long)nv, (long)oi, (long)ov)
  39. #endif
  40.  
  41. #define TV2MS(tv, ms) { \
  42.     (ms) = (tv)->tv_sec * 1000L + (tv)->tv_usec / 1000; \
  43.     if (!(ms) && (tv)->tv_usec) \
  44.         (ms) = 1; \
  45. }
  46.  
  47. #define MS2TV(ms, tv) { \
  48.     (tv)->tv_sec = (ms) / 1000L; \
  49.     (tv)->tv_usec = ((ms) % 1000L) * 1000L; \
  50. }
  51.  
  52. #if 0
  53. int
  54. setitimer (which, new, old)
  55.     int which;
  56.     const struct itimerval *new;
  57.     struct itimerval *old;
  58. {
  59.     unsigned long ni, nv, oi, ov;
  60.     int r;
  61.  
  62.     if (new) {
  63.         TV2MS (&new->it_value, nv);
  64.         TV2MS (&new->it_interval, ni);
  65.     }
  66.     r = Tsetitimer (which, new ? &ni : 0, new ? &nv : 0, &oi, &ov);
  67.     if (r < 0) {
  68.         errno = -r;
  69.         return -1;
  70.     }
  71.     if (old) {
  72.         MS2TV (ov, &old->it_value);
  73.         MS2TV (oi, &old->it_interval);
  74.     }
  75.     return 0;
  76. }
  77.  
  78. int
  79. getitimer (which, old)
  80.     int which;
  81.     struct itimerval *old;
  82. {
  83.     return setitimer (which, 0, old);
  84. }
  85. #endif